<template>
		<view class="main-view">
			<view class="user-text">
				<text class="text">版本号：V1.1.0 Beta</text>
				<text class="text">用户角色：{{userInfoTrans}}</text>
				<text class="text">当前日期：{{$utils.formatDate(Date.now())}}</text>	
				<text class="text">游戏编号:{{currentGameID}}</text>
			</view>
			<view v-if="user.type==='dm'" class="dm-btn">
				<button v-if="gameStatus==='end' || gameStatus==='' " class="viewbtn" type="primary" size="default" @click="createGame">创建游戏</button>
				<button v-else class="viewbtn" type="primary" size="default" @click="continueCurrentGame">继续游戏</button>
			</view>
			<view v-else class="player-btn">
				<button class="viewbtn" type="primary"
					size="default" @click="continueCurrentGame">{{btnText}}</button>
			</view>
			<view>
				<!-- 登录提示窗 -->
				<uni-popup ref="alertDialog" type="dialog">
					<uni-popup-dialog type="warn" title="登录提示" content="当前处于未登录状态,请登录后再开始游戏" @confirm="toLogin">
					</uni-popup-dialog>
				</uni-popup>
			</view>
		</view>
</template>

<script>
	import {querygamelist,submitgamerole,quitgame,addplayeraction} from "@/common/api"
	import {mapState,mapMutations,mapGetters,mapActions} from "@/store/helper/dm"
	import {formatDate} from "@/common/utils"
	import statusBar from "@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-status-bar";
	export default {
		components: {statusBar},
		computed:{
			btnText(){
				return this.gameStatus==='end' || this.gameStatus===''?"开始游戏":"继续游戏"
			},
			...mapState([
				"user",
				"currentGameID",
				"currentGameDTO",
				"gameStatus",
				"gameStageCode"
			]),
			...mapGetters([
				"userInfoTrans",
			])			
		},
		methods: {
			// async queryGamelist(){
			// 	const {code,data,message} =await this.querygamelist({"code":Date.now()})
			// 	if(data.code===200){
			// 		this.setCurrentGameDTO(data.game)
			// 		this.setGameStatus(data.game.processStatus)
			// 	} else{
			// 		console.log(message)
			// 	}
			// },
			createGame(){
				uni.navigateTo({
					url: '/pages/view/dm/create-game'
				})	
			},
			continueCurrentGame(){
				if(this.user.type==="player"){
					uni.navigateTo({
						url: `/pages/view/player/enter-game?queryGameCode=${this.currentGameID}`
					})
					
				} else if(this.user.type==="dm"){
					this.gameStatus==="init"?uni.navigateTo({url: '/pages/view/dm/start-game'})
					:uni.navigateTo({url: '/pages/view/dm/processing-game'})
				} else if(this.user.type==="guest"){
					this.$refs.alertDialog.open()
				}
			},
			toLogin() {
				uni.navigateTo({
					url: '/pages/ucenter/ucenter'
				})
			},
			...mapMutations([
				"setCurrentGameDTO",
				"setGameStatus"
			])
		},
	}
</script>

<style lang="scss" scoped>
	.main-view {
		display: flex;
		flex-direction: column ;
		background: url(https://s3.bmp.ovh/imgs/2022/03/880ad8a2bde6b35d.png)  scroll 0 0;
		background-size: contain;
		height: 1500rpx;
		
		.player-btn,
		.dm-btn {
			display: flex;
			align-items: center;
			justify-content: center;
			vertical-align: middle;
			margin-top: 300rpx;
			flex:1;

			/deep/.viewbtn {
				background-color:#f0f130;
				border: 3px solid #201C2A;
				border-radius: 15rpx;
				color: #201C2A;
				font-weight: 700;
			}
		}

		.user-text {
			display: flex;
			flex-direction: column ;
			align-items: center;
			justify-content: center;
			margin-top: 362.31rpx ;
			color: #f0f130;
			font-weight: 400;
			.text{
				margin: 5px 0 ;
			}
		}
	}
</style>
